package com.alex.service.Search_Plans;

import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.MatchPhraseQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;

import static com.alex.utils.MyUtils.zsout;


/**
 * @Author: 张福垒
 * @Date: 2024/11/27 16:32
 * @Description: [全部] 精确命中
 * @phone: 13864677931
 */
public class All_Field_Term_query {
    /**
     * 针对主题的 不分词的检索方法 根据输入的单次或者汉字长度来判断需要命中X/Y 或者 X% 之多少的数字
     *
     * @param freeWord
     * @return
     */
    public static Query all_field_term_query(String freeWord, boolean printLog) {
        zsout("[AllField][精确]   " + freeWord, printLog);
        BoolQuery.Builder builder = new BoolQuery.Builder();


        builder.should(MatchPhraseQuery.of(i -> i.field("title").query(freeWord.toLowerCase()).slop(0))._toQuery());
        builder.should(MatchPhraseQuery.of(i -> i.field("cn_ti").query(freeWord.toLowerCase()).slop(0))._toQuery());

        builder.should(MatchPhraseQuery.of(i -> i.field("journal").query(freeWord.toLowerCase()).slop(0))._toQuery());
        builder.should(MatchPhraseQuery.of(i -> i.field("key_word_list").query(freeWord.toLowerCase()).slop(0))._toQuery());

        builder.should(MatchPhraseQuery.of(i -> i.field("ab").query(freeWord.toLowerCase()).slop(0))._toQuery());
        builder.should(MatchPhraseQuery.of(i -> i.field("cn_ab").query(freeWord.toLowerCase()).slop(0))._toQuery());




        return builder.build()._toQuery();

    }

}
